package com.dark.simple;

import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.generated.AlreadyAliveException;
import backtype.storm.generated.InvalidTopologyException;
import backtype.storm.topology.TopologyBuilder;

/**
 * Hello world!
 *
 */
public class LocalTestDemo {
    public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException,Exception {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("randomHelloWorld", new HelloWorldSpout(), 1);
        builder.setBolt("HelloWorldBolt", new HelloWorldBolt(), 1).shuffleGrouping("randomHelloWorld");
        Config conf = new Config();
        conf.setDebug(true);
        /**
         * 这部分代码是本地调试使用的代码.
         */
        LocalCluster cluster = new LocalCluster();

        //建议加上这行，使得每个bolt/spout的并发度都为1
        conf.put(Config.TOPOLOGY_MAX_TASK_PARALLELISM, 1);

        //提交拓扑
        cluster.submitTopology("HelloWorld", conf, builder.createTopology());

        //等待1分钟， 1分钟后会停止拓扑和集群， 视调试情况可增大该数值
        Thread.sleep(60000);

        //结束拓扑
        cluster.killTopology("HelloWorld");

        cluster.shutdown();
    }
}
